/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

/**
 * Created by yfyang on 4/12/14.
 */
define([ 'adminapp'], function ($app) {
    // nav menu
    $app.navactive('brand');

    var action_tpl = Handlebars.compile($(g.actiontpl).html());
    var product_tpl = Handlebars.compile($(g.producttpl).html());

    var $listtable = $app.listtable({
        'sAjaxSource' : g.ctx + "admin/brand/list",
        'fnServerParams': function( aoData){
            var sd = $('#search_form').serializeJSON();
            $.each(sd, function(name, val){
                aoData.push({"name": name, "value": val});
            });
        },
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'id' },
            {'mDataProp': 'name' },
            {'mDataProp': 'e_name' },
            {'mDataProp': 'floor' },
            {'mDataProp': 'format' },
            {'mDataProp': 'logo' },
            {'mDataProp': 'description' },
            {'mDataProp': 'picture' },
            {'mDataProp': 'contact' },
            {'mDataProp': 'location' },
            {'mDataProp': 'id' },
            {'mDataProp': 'integrity' },
            {'mDataProp': 'mall' }
        ],
        'aoColumnDefs': [
            { 'bSearchable': false, 'bVisible': false, 'aTargets': [ 2,7,8,9,14 ] },
            {
                'aTargets': [5],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return full['floor_name'];
                }
            },
            {
                'aTargets': [6],
                'mData'   : null, 'bSearchable': false,
                'mRender' : function (data, type, full) {
                    return full['format_name'];
                }
            },
            {
                'aTargets' : [12],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    // product link
                    return product_tpl(full);
                }
            },
            {
                'aTargets' : [15],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'brand-list');

    $('#search_btn').on('click', function (e) {
        e.preventDefault();
        $listtable.fnReloadAjax();
    });
    return {};
});